<template>
  <div class="page-container">
    <div class="page-content">
      <div class="panel-container">
        <div class="panel-content">
          <!--搜索-->
          <SearchUiNew ref="SearchUiNew" style="margin-top: 10px" :searchFormArr="searchFormArr" @searchParma="searchParma"></SearchUiNew>
        </div>
      </div>
      <!--数据信息-->
      <div class="panel-container no-margin">
        <div class="panel-line" style="margin-bottom: 10px">
          <el-radio-group v-model="tabActive" style="margin-right: 30px" size="mini" @change="handleTabChange">
            <el-radio-button v-for="item in tabList" :key="item.value" :label="item.value">{{ item.label }}</el-radio-button>
          </el-radio-group>
        </div>
        <el-table stripe :data="dataList" size="mini" :header-cell-style="{ background: '#F5F5F5', color: '#000000' }" ref="table" style="width: 100%" v-loading="dataListLoading">
          <af-table-column align="center" fixed="left" header-align="center" show-overflow-tooltip label="日期" prop="key"></af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="员工姓名" prop="user_name"></af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="添加量" prop="1"></af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="编辑量" prop="2"></af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="删除量" prop="3"></af-table-column>
        </el-table>
        <el-pagination
          small
          background
          :current-page="pageNumber"
          :page-size="pageSize"
          :page-sizes="[10, 20, 50, 100]"
          :total="pageTotal"
          @current-change="currentChangeHandle"
          @size-change="sizeChangeHandle"
          layout="total, sizes, prev, pager, next, jumper"
          style="margin-top: 20px; text-align: right"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { apiInnerWorkCountList } from '@/api/biddingNotice'

export default {
  name: 'InnerNoticeStatistics',
  components: {},
  data() {
    return {
      tabActive: 1,
      tabList: [
        { value: 1, label: '按日' },
        { value: 2, label: '按周' },
        { value: 3, label: '按月' },
      ],
      searchFormArr: [
        {
          fieldName: '员工:',
          type: 'select',
          field: 'user_id',
          option: [],
        },

        {
          fieldName: '日期:',
          type: 'timePicker',
          field: 'time',
          placeholder: '请选择日期',
          timeType: 'daterange',
          format: 'yyyy-MM-dd',
        },
      ],
      searchParams: {
        user_id: '',
        start_time: '',
        end_time: '',
      },
      dataList: [],
      pageNumber: 1,
      pageSize: 10,
      pageTotal: 0,
      dataListLoading: false,
    }
  },
  activated() {
    this.$refs.table && this.$refs.table.doLayout()
  },
  mounted() {
    this.getSelectList()
    this.getDataList()
  },
  destroyed() {},
  methods: {
    // 获取下拉数据
    getSelectList() {
      this.$store.dispatch('select/getUserList').then((res) => {
        const formItem = this.searchFormArr.find((item) => item.field === 'user_id')
        formItem.option = res
      })
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true
      let info = { pageNumber: this.pageNumber, pageSize: this.pageSize, method: this.tabActive }
      info = Object.assign(info, this.searchParams)
      apiInnerWorkCountList(info)
        .then((res) => {
          const { data, total } = res
          this.dataList = data
          this.pageTotal = total
          this.dataListLoading = false
          this.$refs.table && this.$refs.table.doLayout()
        })
        .catch((e) => {
          this.dataList = []
          this.pageTotal = 0
          this.dataListLoading = false
        })
    },
    // 列表查询
    searchParma(e) {
      let list = ['time']
      this.searchFormArr.forEach((item) => {
        if (list.includes(item.field)) return
        if (e[item.field]) {
          this.searchParams[item.field] = e[item.field]
        } else {
          this.searchParams[item.field] = ''
        }
      })
      if (e.time) {
        this.searchParams.start_time = e.time[0]
        this.searchParams.end_time = e.time[1]
      } else {
        this.searchParams.start_time = this.searchParams.end_time = ''
      }
      this.pageNumber = 1
      this.getDataList()
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageNumber = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageNumber = val
      this.getDataList()
    },
    // 切换tab
    handleTabChange(val) {
      this.pageNumber = 1
      this.getDataList()
    },
  },
}
</script>
